﻿using System;
using YTE.Control;
using 右下角弹窗.DiagShow;

namespace LD.Host
{
    public partial class FrmVariableEdit : FrmOKCancel
    {

        public FrmVariableEdit()
        {
            InitializeComponent();
            this.Shown += FrmVariableEdit_Shown;
            this.btn_ok.Click += Btn_ok_Click;
            Loader();
        }
        public FrmVariableEdit(string name) : this()
        {
            //if (result != null)
            //{
            //    this.txt_name.Text = name;
            //    this.txt_name.ReadOnly = true;
            //    this.txt_val.Text = result.Value;
            //    this.cob_dataType.Text = result.DataType;
            //    this.cob_group.SelectedValue = result.PId;
            //}

        }
        private void FrmVariableEdit_Shown(object sender, EventArgs e)
        {
        }

        private void Btn_ok_Click(object sender, EventArgs e)
        {
            Dialog dialog = new Dialog();
            string name = this.txt_name.Text.Trim();
            string val = this.txt_val.Text.Trim();
            bool isHide = this.sw_isHide.Checked;
            string dataType = this.cob_dataType.Text;
            int pid = this.cob_group.SelectedValue == null ? 0 : (int)this.cob_group.SelectedValue;
            //检查唯一性
            if (Cache.GetCache(name) != null)
            {
                if (this.txt_name.ReadOnly)
                {

                }
                else
                    dialog.Warning("数据已存在");
            }
            else
            {

                dialog.Success("保存成功");
            }

            this.Close();
        }

        public void New()
        {

        }
        private void Loader()
        {
            this.cob_group.DisplayMember = "Name";
            this.cob_group.ValueMember = "Id";
        }
    }
}
